import React, { useEffect, useState } from "react";
import { Descriptions, Card, Button } from "antd";
import { useNavigate, useParams } from "react-router-dom";
// 引入api请求
import { hospitalInformationRequest } from "@/api/hospital/hospitalList";
// 引入类型判断
import { hospitalInformationType } from "@/api/hospital/model/hospitalListTypes";
export default function HospitalShow() {
  const navigate = useNavigate();
  // 接受到传递过来的param值 可以通过id请求获取数据
  const { id } = useParams();
  //渲染数据
  const [hospitalData, setHospitalData] = useState<hospitalInformationType>({});
  // 刚开始时请求获取数据
  useEffect(() => {
    const res = async () => {
      const re = await hospitalInformationRequest(id as string);
      setHospitalData(re);
    };
    res();
  }, []);
  return (
    <div>
      {/* column控制一行的列数 */}
      <Card>
        <Descriptions title="基本信息" bordered column={2}>
          <Descriptions.Item label="医院名称">
            {hospitalData.hospital?.hosname}
          </Descriptions.Item>
          <Descriptions.Item label="医院logo">
            {" "}
            {hospitalData.hospital?.logoData ? (
              <img
                width={100}
                src={`data:image/jpeg;base64,${hospitalData.hospital?.logoData}`}
                alt=""
              />
            ) : (
              ""
            )}
          </Descriptions.Item>
          <Descriptions.Item label="医院编码">
            {hospitalData.hospital?.hoscode}
          </Descriptions.Item>
          <Descriptions.Item label="医院地址">
            {hospitalData.hospital?.param.fullAddress}
          </Descriptions.Item>
          <Descriptions.Item label="坐车路标" span={2}>
            {hospitalData.hospital?.route}
          </Descriptions.Item>
          <Descriptions.Item label="医院简介" span={2}>
            {hospitalData.hospital?.intro}
          </Descriptions.Item>
        </Descriptions>
        <Descriptions
          title="预约规则信息"
          bordered
          column={2}
          style={{ marginTop: "30px" }}
        >
          <Descriptions.Item label="预约周期">
            {hospitalData.bookingRule?.cycle}
          </Descriptions.Item>
          <Descriptions.Item label="放号时间">
            {hospitalData.bookingRule?.releaseTime}
          </Descriptions.Item>
          <Descriptions.Item label="挂停时间">
            {hospitalData.bookingRule?.stopTime}
          </Descriptions.Item>
          <Descriptions.Item label="退号时间">
            {hospitalData.bookingRule?.quitTime}
          </Descriptions.Item>
          <Descriptions.Item label="预约规则" span={2}>
            {hospitalData.bookingRule?.rule.map((item, index) => {
              return <p key={index}>{item}</p>;
            })}
          </Descriptions.Item>
        </Descriptions>
        {/* 点击返回到上一层 */}
        <Button
          style={{ marginTop: "30px" }}
          onClick={() => {
            navigate(-1);
          }}
        >
          返回
        </Button>
      </Card>
    </div>
  );
}
